package yudisium;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



import database.OraConnection;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

public class PengendaliPendaftaranYudisium {

    public static ArrayList<Mahasiswa> DAFTAR_MAHASISWA = new ArrayList<Mahasiswa>();

    public static void tambahMahasiswa(Mahasiswa mahasiswa) {
        DAFTAR_MAHASISWA.add(mahasiswa);
    }

    public static void tambahTabelMahasiswa(Mahasiswa mahasiswa) {
        Connection conn = OraConnection.open("jdbc:oracle:thin:@172.23.9.185:1521:orcl","MHS115314033", "MHS115314033");
        Statement statement = null;
        try {
            statement = conn.createStatement();
            String sql = "insert into yudisium (nama, nim, nomor_hp, prodi,email,  periode_bulan," +
                                                "periode_tanggal,"
                                                + "bebaspinjam_lab, bebaspinjam_dosen,"
                                                + "bukti_kp) values ('"
                                                + mahasiswa.getNama() + "','" + mahasiswa.getNim() + "','"
                                                + mahasiswa.getNope() + "','" + mahasiswa.getProdi() + "','" 
                                                + mahasiswa.getPeriode() + "','"
                                                + mahasiswa.getTanggal()+ "','"
                                                + mahasiswa.getBebaspinjamLab() + "','"
                                                + mahasiswa.getBebaspinjamDosen() + "','"
                                                + mahasiswa.getLaporanKP();
                                               
            //System.out.println(sql);
            statement.executeUpdate(sql);
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(PengendaliPendaftaranYudisium.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static void simpanTabelMahasiswa() {
        if (DAFTAR_MAHASISWA.isEmpty()) {
            JOptionPane.showMessageDialog(null, "Daftar Mahasiswa Kosong");
        } else {
           Connection conn = OraConnection.open("jdbc:oracle:thin:@172.23.9.185:1521:orcl","MHS115314033", "MHS115314033");
            Statement statement = null;
            try {
                statement = conn.createStatement();
            } catch (SQLException ex) {
                Logger.getLogger(PengendaliPendaftaranYudisium.class.getName()).log(Level.SEVERE, null, ex);
            }
            for (int i = 0; i < DAFTAR_MAHASISWA.size(); i++) {
                String sql = "insert into YUDISIUM (nama, nim, nomor_hp, email, prodi, periode_bulan," +
                                                    "periode_hari, periode_tanggal) values ('" +
                                                    DAFTAR_MAHASISWA.get(i).getNama() + "','" +
                                                    DAFTAR_MAHASISWA.get(i).getNim() + "','" +
                                                    DAFTAR_MAHASISWA.get(i).getNope() + "','" +
                                                    DAFTAR_MAHASISWA.get(i).getProdi() + "','" +
                                                    DAFTAR_MAHASISWA.get(i).getPeriode() + "','" +                                                    
                                                    DAFTAR_MAHASISWA.get(i).getTanggal() + "')";
                try {
                    statement.executeUpdate(sql);
                } catch (SQLException ex) {
                    Logger.getLogger(PengendaliPendaftaranYudisium.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            try {
                conn.close();
            } catch (SQLException ex) {
                Logger.getLogger(PengendaliPendaftaranYudisium.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

